//
//  ImgViewCell.m
//  quxiangtao
//
//  Created by HHuajiang on 2018/12/18.
//  Copyright © 2018 shanhaijin. All rights reserved.
//

#import "ImgViewCell.h"

@implementation ImgViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        UIImageView *img = [[UIImageView alloc] init];
        img.backgroundColor = Colordddddd;
        [self.contentView addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_offset(0);
        }];
        MKViewBorderRadius(img, 5, 0, WhiteColor);
        
        self.img = img;
        
        UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [selectButton setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
        [selectButton setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        [self.contentView addSubview:selectButton];
        [selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-Margin);
            make.top.mas_equalTo(Margin);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        [selectButton addTarget:self action:@selector(selectButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.selectButton = selectButton;
    }
    return self;
}

- (void)setImageUrl:(NSString * _Nonnull)imageUrl WithIndePathRow:(NSInteger)index ButtonSelectStatus:(NSString *)status{
    [self.img sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
    self.selectButton.selected = [status intValue];
    self.selectButton.tag = index;
}

- (void)selectButtonClick:(UIButton *)button {
    if (self.buttonSelectClickBlock) {
        self.buttonSelectClickBlock(button.tag);
    }
}
@end
